package top.lishuoboy.knife4j.swagger3_0_0.exception;

import lombok.Getter;
import top.lishuoboy.knife4j.swagger3_0_0.enums.Code;

import javax.validation.constraints.NotNull;

@Getter
public class MyApiException extends RuntimeException {
    /** 响应状态码（0：成功，其他：失败） */
    @NotNull
    private Integer code;
    /** 响应消息（对响应码的补充说明） */
    private String msg;

    // 手动设置异常
    public MyApiException(Integer code, String msg) {
        // message用于用户设置抛出错误详情
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    public MyApiException(String msg) {
        super(msg);
        this.code = Code.FAIL_CLIENT.code;
        this.msg = msg;
    }
}